#!/usr/bin/env python3

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = cv.imread('../pic/图像梯度.png', 0)

sobelx = cv.Sobel(img, cv.CV_64F, 1, 0, ksize=5)
sobely = cv.Scharr(img, cv.CV_64F, 0, 1)

sobelxy = cv.addWeighted(sobelx, 0.5, sobely, 0.5, 0)

laplacian = cv.Laplacian(img, cv.CV_64F)

plt.subplot(2, 3, 1), plt.imshow(img, cmap='gray')
plt.title('Original'), plt.xticks([]), plt.yticks([])
plt.subplot(2, 3, 2), plt.imshow(sobelx, cmap='gray')
plt.title('Sobel X'), plt.xticks([]), plt.yticks([])
plt.subplot(2, 3, 3), plt.imshow(sobely, cmap='gray')
plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])
plt.subplot(2, 3, 4), plt.imshow(sobelxy, cmap='gray')
plt.title('Sobelxy'), plt.xticks([]), plt.yticks([])

plt.subplot(2, 3, 5), plt.imshow(laplacian, cmap='gray')
plt.title('Laplacian'), plt.xticks([]), plt.yticks([])
plt.show()
